// 两数之和
/**
 * @param {number[]} numbers
 * @param {number} target
 * @return {number[]}
 */
 var twoSum = function(numbers, target) {
    /*let ans = new Map();
    let n = numbers.length;
    for(let i=0;i<n;i++) {
        if(ans.has(target-numbers[i])) {
           return [ans.get(target-numbers[i])+1,i+1];
        }
        else{
            ans.set(numbers[i],i)
        }
    }*/
    /*let l = 0;
    let r = numbers.length-1;
    while(l<r) {
        if(numbers[l]+numbers[r]===target) {
            return [l+1,r+1];
        }
        else if(numbers[l]+numbers[r]>target) {
            r--;
        }
        else
    {
        l++;
    }
    }
    */
     for(let i = 0; i < numbers.length; i++){
            let targ = target - numbers[i]
            let l = i + 1, r = numbers.length - 1
            while(l <= r){
                let mid = Math.floor((l + r) / 2)
                let num = numbers[mid]
                if(targ === num) return [i + 1, mid + 1]
                if(targ > num){
                    l = mid + 1
                }else{
                    r = mid - 1
                }
            }
        }
    };